package config

import (
	"io/ioutil"

	"github.com/sirupsen/logrus"
	"gopkg.in/yaml.v2"
)

var Instance *Config

type Config struct {
	Env        string `yaml:"Env"`
	BaseUrl    string `yaml:"BaseUrl"`
	Port       string `yaml:"Port"`
	Salt       string `yaml:"Salt"`
	Code       string `yaml:"Code"`
	Key        string `yaml:"Key"`
	LogFile    string `yaml:"LogFile"`
	StaticPath string `yaml:"StaticPath"`
	IpDataPath string `yaml:"IpDataPath"`
}

func Init(filename string) *Config {
	Instance = &Config{}
	if yamlFile, err := ioutil.ReadFile(filename); err != nil {
		logrus.Error(err)
	} else if err = yaml.Unmarshal(yamlFile, Instance); err != nil {
		logrus.Error(err)
	}
	return Instance
}
